/*************************************************************************
	> File Name: P1115-2.cpp
	> Author: 
	> Mail: 
	> Created Time: 
 ************************************************************************/
#include <iostream>
#define MAX_N 1000000
using namespace std;

int dp[MAX_N + 5] = {0};

int main() {
    int n; cin >> n;
    for (int i = 1; i <= n; i++) cin >> dp[i];
    int start = 1, end = 1, p = 1;
    int maxsum = dp[1];
    for (int i = 2; i <= n; i++) {
        if (dp[i - 1] + dp[i] >= dp[i]) dp[i] = dp[i - 1] + dp[i];
        else p = i;
        if (dp[i] > maxsum) {
            maxsum = dp[i];
            start = p;
            end = i;
        }
    }
    cout << maxsum << endl;
    return 0;
}
